{{define "tag.add"}}
<!DOCTYPE html>
<html>
<style>
    #paigusu-screen {
        top: 20%;
    }
</style>
<head>
    <meta charset="utf-8">
    <title>标签添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/statics/third-pkg/layui/css/layui.css">
    <link rel="stylesheet" href="/statics/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权重</label>
            <div class="layui-input-block">
                <input type="number" name="weight"  placeholder="请输入权重" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">颜色</label>
            <div class="layui-input-block">
                <input type="hidden" name="color" value="#1aa094">
                <div id="test1"></div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script src="/statics/third-pkg/layui/layui.js"></script>
    <script src="/statics/admin/js/lay-config.js?v=2.0" charset="utf-8"></script>
    <script>

        layui.use(['form','request','layer','miniTab',"common","colorpicker"], function() {
            var form = layui.form,
                layer = layui.layer,
                miniTab = layui.miniTab,
                $=layui.$,
                colorpicker = layui.colorpicker,
                common=layui.common,
                request=layui.request;
            //渲染
            colorpicker.render({
                elem: '#test1',
                color:"#009cff"
                ,change: function(color){
                    $("input[name='color']").val(color)
                }//绑定元素
            },);
            //监听提交
            form.on('submit(saveBtn)', function(data) {
                var subdata={
                    ...data.field,
                    "weight":Number.parseInt(data.field["weight"])
                }
                request.post('admin/tag/add',subdata).then(function (response) {
                    if(response.data.code==0){
                        localStorage.setItem("tag",common.generateUUID())
                        layer.msg('添加文章标签成功',{
                            time:1000
                        },function (){
                            miniTab.deleteCurrentByIframe();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.location.href="/admin/tag/list";
                        })
                    }else{
                        layer.msg(response.data.msg);
                    }
                }).catch(function (error) {
                    console.log(error)
                    layer.msg('提交失败');
                });
            });

        });
    </script>
</body>

</html>
{{ end }}